/*
 * I2CLed.java
 *
 * Created on April 6, 2004, 1:35 AM
 */

package Tini;

/**
 *
 * @author  raph
 */
public class I2CLed extends javax.swing.JFrame {
    
    /** Creates new form I2CLed */
    public I2CLed() {
        initComponents();
        b1=true;
        b2=true;
        try {
            s=new java.net.Socket("172.16.0.3",3333);
            System.out.println(s);
        }
        catch(java.io.IOException e){System.out.println("erreur ouverture socket");}
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jTextArea1 = new javax.swing.JTextArea();

        getContentPane().setLayout(null);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("I2C -Tini Evaluation");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        jCheckBox1.setText("Led1");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        getContentPane().add(jCheckBox1);
        jCheckBox1.setBounds(60, 50, 55, 23);

        jCheckBox2.setText("Led2");
        jCheckBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox2ActionPerformed(evt);
            }
        });

        getContentPane().add(jCheckBox2);
        jCheckBox2.setBounds(210, 50, 55, 23);

        jTextArea1.setEditable(false);
        getContentPane().add(jTextArea1);
        jTextArea1.setBounds(30, 140, 300, 110);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);
    }//GEN-END:initComponents
    
    private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox2ActionPerformed
        // TODO add your handling code here:
        
        this.jTextArea1.append("led2");
        try {
            if (b1) s.getOutputStream().write(0);
            else s.getOutputStream().write(1);
            b1=!b1;
        }
        catch(java.io.IOException e){System.out.println("erreur ecriture socket");}
        
    }//GEN-LAST:event_jCheckBox2ActionPerformed
    
    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        // TODO add your handling code here:
        this.jTextArea1.append("led1");
        try {
            if (b2) s.getOutputStream().write(2);
            else s.getOutputStream().write(3);
            b2=!b2;
        }
        catch(java.io.IOException e){System.out.println("erreur ecriture socket");}
        
        
    }//GEN-LAST:event_jCheckBox1ActionPerformed
    
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
        System.exit(0);
    }//GEN-LAST:event_exitForm
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new I2CLed().show();
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables
    private java.net.Socket s;
    private boolean b1,b2;
}
